<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 使括号有效的最少添加 -->
    <script>
      var minAdd = function (s) {
        var left = 0,
          right = 0
        Array.prototype.forEach.call(s, v => {
          if (v === '(') {
            ++left
          } else {
            if (left > 0) --left
            else ++right
          }
        })
        return left + right
      }
      // console.log(minAdd('())'))
      console.log(minAdd('((('))
    </script>
  </body>
</html>
